<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>-=SOEN 6441 - Documentation Phase1=-</title>
        <meta name="generator" content="TextMate http://macromates.com/">
        <meta name="author" content="Buthainah Aldosary">
        <link rel="stylesheet" type="text/css" href="style.css">
        <!-- Date: 2013-05-15 -->
    </head>
    <body>
        <div align="center">
            <h1>SOEN 6441- 1 2013 Collaborative Email Client</h1>
            <br>
            <br>
            <table border="1">
                <tr>
                    <th>Name</th>
                    <th>ID</th>
                </tr>
                <tr>
                    <td>Buthainah Aldosary</td>
                    <td>6302459</td>
                </tr>
                <tr>
                    <td>Hadi Karesli</td>
                    <td>9317201</td>
                </tr>
                <tr>
                    <td>Musab M Mirza</td>
                    <td>6367216</td>
                </tr>
                <tr>
                    <td>Sukhjinder K. Narula</td>
                    <td>5285348</td>
                </tr>
            </table>


            <p><b>Due Date: May 22, 2013</b></p>	
            <p><b>Version 1.0</b></p>
        </div>	


        <h2>Introduction</h2>
        <p>This design document outlines the architectural and component design of the Collaborative Email Client system using textual descriptions and supporting diagrams. A high level Modified MVC architecture of the system is presented, internal design of each of its subsystem and their respective classes as well as design choices for the persistent data layer and the testing approach used.
            The goal of this document is to a higher vision of the development of the software; provide an overall structure and the reasons for this design.
        </p>

        <h2>Functional Requirements</h2>
        <p>The functional requirements for phase 1 of the project include:</p>
        <ul>
            <li>Compose new email.</li>
            <li>Save draft email.</li>
            <li>Display inbox folder hierarchy. </li>
            <li>Create sub folders.</li>
            <li>Move mail to sub folders.</li>
            <li>Send mail functionality that moved email to a Sent and ToSend folder.</li>
            <li>Delete email from folders.</li>
            <li>Delete folders except top-level inbox.</li>
            <li>All functionalities should have menu, right mouse click and hot keys.</li>
        </ul>










        <h2>Architectural Design</h2>
        <p>The architecture of our system adopts the widely used Model-View-Controller (MVC) architecture that separates the data from the user’s interactions with it. However, to have a cleaner separation of concerns, the Modified MVC (MMVC) has been used in our system. The controller sits in between the view and the model where it mediates the flow of data between model and view objects in both directions. The following diagram illustrates the MMVC architecture.</p>

        <div align="center">
            <img src="img/modified_mvc.jpg"  width="350" height="250">

        </div>
        <h2>Detailed Design</h2>

        <h3> Model Subsystem </h3>

        <p>The model sub-system contains the main data structures for the system.  It is designed where the controller can directly access the data to be read and modified. The model contains separate classes for the main concepts of the system such as Email, Folder, User and User Account. It also contains a class EmailBuilder that applies the builder design pattern in creating an email object with multiple parameters as well as ModelException class that extends the Exception class and stores an exception message in a String object.</p>

        <h4>User Class </h4>
        The User class contains attributes for a user object. They include the user id, name, User SQL Data Access Object (UserSQLDao) and a list of folders that are associated with the current user. The id of the user is automatically created upon insertion into the database. The UserSQLDao is used to save and fetch User data from the database. 

        <h4> Folder Class </h4>
        The Folder class contains attributes for a folder object. These attributes include the folder id, name, userId, parentId, Folder SQL Data Access Object (FolderSQLDao) and a list of Email objects that currently reside in that folder. The id of the folder is automatically created upon insertion into the database.  A folder object also carries the id of its parent folder as well as the id of the user it belongs to. The FolderSQLDao is used to save and fetch Folder data from the database.


        <h4> Email Class </h4>
        The Email class contains attributes for an email object. These attributes include the 
        Email id, to, from, subject, body, timestamp, folderId, an Email SQL Data Access Object (EmailSQLDao) and a Boolean variable read to indicate if the email has been read or not. The id of the Email is automatically created upon insertion into the database. The folderId refers to the id of the folder the email resides in, the EmailSQLDao is used to save and fetch Email data from the database.

        <h3>View Subsystem </h3>
        <p>The view subsystem is updated when the controller subsystem fetched data from the model and passes it on to each view.  The following describes each view and what it contains:</p>

        <h4> App View </h4>
        Contains the Main Menu View, Navigation View, Listing and Preview View. It also sets the main properties of the view, which are the title, size, visibility and location
        <h5> Navigation View </h5>
        Contains a compose new email button and a create new folder button as well as text field for new folder name and a drop down list to select the parent folder.
        <h5> Listing View </h5>
        The listing view contains a list of all the emails as well as a delete and move button.
        <h5> Preview View </h5>
        The preview view displays the current selected email from the listing view. It has text fields corresponding to the to, from, date, and subject fields as well as a text area for the body field.
        <h5>Main Menu View </h5>
        The mail menu view contains a file menu with an exit item and a help menu with an about item.

        <h4> Compose Mail View </h4>
        The compose mail view serves as a container for the compose mail main menu and email editor panel.
        <h5> Compose Mail Main Menu View </h5>
        The compose mail main menu view contains a file menu with new message, save mail, send mail now, send mail later and close window items. As well as edit menu with copy, cut, paste and select all items.
        <h5> Email Editor Panel </h5>
        The email editor panel contains text fields for to and from email addresses and a subject field. It also contains a text pane for the body with a scroll pane and text labels for to, from and subject as well as buttons to send and save the email.

        <h4> About Cool Mail View </h4>
        This view is a dialog containing information about the development team.

        <h3> Controller Subsystem</h3>
        <p>The Controller subsystem contains the following important classes:</p>
        <h4> AppController</h4>
        The app controller has direct access to the app model and app view.  Upon initialization, it also initializes the listening, menu, navigation and preview controllers as well as load the user and finally setup and initialize the app view.
        <h4> ComposeMailController</h4>
        This controller is linked to the app model and the ComposeMailView. It assigns handlers to events such as save mail and send mail.
        <h4> ListingController</h4>
        This controller is linked to the app model and the app view. It assigns handlers to events such as move and delete button clicks, right clicking on a row in the emails list and detecting email selection.
        <h4> NavigationController</h4>
        This controller is linked to the app model and the app view. It assigns handlers to events such as compose email button click, right clicking on a folder, creating a new folder, deleting a folder, right clicking on a folder name, renaming a folder and creating a sub folder.
        <h4> PreviewController</h4>
        This controller is linked to the app model and app view. It sets an email object to preview in the preview pane.


        <h3> Dao Subsystem </h3>
        <p>The Dao subsystem contains the following important classes:</p>
        <h4> DaoFactory </h4>
        The constructor of a DaoFactory class first creates a file directory if one does not exist and initialized the database as well as set up the tables if it does not exist. The factory also creates and returns EmailSqlDao, UserSqlDao and FolderSqlDao objects that are connected to the database.
        <h4> UserSqlDao</h4>
        The UserSqlDao object interacts with the database directly and implements functions namely create a new user, update an existing user, delete a user, find user by ID and find user by name.
        <h4> FolderSqlDao</h4>
        The FolderSqlDao object interacts with the database directly and implements functions namely create a new folder, find a folder by id, update a folder, delete a folder, find a folder given a user id and delete a folder given a user id.
        <h4> EmailSqlDao</h4>
        The EmailSqlDao object interacts with the database directly and implements functions namely create a new email, find an email given it’s id, update an existing email, delete an email, find an email given a folder id and delete an email given its folder id.



        <h2>Persistent Layer</h2>
        <p>For persistent layer, we have used SQLite which is a very lightweight open source single file database. To establish a connection with the database, we are using SQLite JDBC driver. The reason for choosing a database over file system are:
        <ul>
            <li>We have more experience with database programming </li>
            <li>CRUD and relational mapping is easier to implement in a database.</li>
            <li>There is also a high resemblance between the application's models and individual tables in the database which makes code understanding easier.</li>
        </ul>
    </p>


    <h2>Testing</h2>

    <p>Unit testing has been applied to our system using the JUnit 4 Framework for the Java Programming Language. Due to the large number of methods in our system, only a selected set of methods were tested to assure fit for use. Additionaly, methods that interact with the database directly were excluded from the selected set as they would need a different approach for testing (e.g: using test doubles, mock objects). EclEmma Java code coverage plug-in for eclipse was used to measure the percentage of code coverage. The total percentage of code coverage is 48.3%</p>

    <div align="center">
        <img src="img/Test Coverage.jpg"  width="700" height="500">
    </div>

    
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="js/custom.js" ></script>
    
    
</body>
</html>
